<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>把URL参数解析成一个对象</title>
</head>
<body>
    
</body>
</html>
<script>
    function jiexi(url) {
        let obj = {}
        let arr = []
        let arr2 = []
        let str = ''
        let str2 = ''
        for (let i = 0; i < url.length; i++) {
            if (url.charCodeAt(i) >= '97' && url.charCodeAt(i) <= '122') {
                str += url[i]
            } else if (url[i] == '=') {
                arr.push(str)
                str = ''
            } else if (isNaN(url[i]) && url[i] != '&') {
                str2 += url[i]
            } else if (url[i] >= 0 && url[i] <= 9) {
                str2 += url[i]
            } else if (url[i] == '&') {
                arr2.push(str2)
                str2 = ''

            }
        }
        arr2.push(str2)
        for (let i = 0; i < arr.length; i++) {
            obj[arr[i]] = arr2[i];
        }
        return obj
    }
    //解析成{name:'张三',age:18}
    let url = `name=张三&age=18`
    console.log(jiexi(url));
</script>